#include "sk_game_item_proxy.h"
#include "sk_creation_params.h"


namespace sk
{

GameItemProxy::GameItemProxy(GameItem * parent, QString n, int ind /*= 0*/)
    :
GameItem(parent, ind),
name(n)
{

}

GameItemType GameItemProxy::type()
{
    return IT_Proxy;
}

int GameItemProxy::numChilds()
{
    GameItem * p = parent();
    if (0 == p)
    {
        Q_ASSERT(false);
        return 0;
    }
    return p->numChildsForProxy(index());
}

GameItem * GameItemProxy::getChildItem(int ind)
{
    GameItem * p = parent();
    if (0 == p)
    {
        Q_ASSERT(false);
        return 0;
    }
    GameItem * res = p->getChildItemForProxy(index(), ind);
    if (res)
    {
        _childItems[ind] = res;
    }
    return res;
}

void GameItemProxy::doCloneChild(int ind)
{
    GameItem * p = parent();
    if (0 == p)
    {
        Q_ASSERT(false);
        return;
    }
    p->doCloneChildForProxy(index(), ind);
}

GameItem * GameItemProxy::createItem(void * params)
{
    SimpleItemParam * pr = static_cast<SimpleItemParam*>(params);
    Q_ASSERT(pr->type == IT_CLONE);
    return cloneChild(pr->ind);
}

void GameItemProxy::doDeleteChild(int ind)
{
    GameItem * p = parent();
    if (0 == p)
    {
        Q_ASSERT(false);
        return;
    }
    return p->doDeleteChildForProxy(index(), ind);
}

void GameItemProxy::doSwapChilds(int i, int j)
{
    GameItem * p = parent();
    if (0 == p)
    {
        Q_ASSERT(false);
        return;
    }
    return p->doSwapChildsForProxy(index(), i, j);
}

void GameItemProxy::paint(QPainter * painter, const QStyleOptionViewItem & option, int row, int column)
{
    paintText(painter, option, &name, row, column);
}

} // namespace sk
